using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MobProjectile:Projectile {

	public Mob mob { get; private set; }
	public bool doUpdateHit;

	protected override void Init() {
		base.Init();
		doUpdateHit=false;
		mob=GetComponent<Mob>();
		MobEventHelper.damaging.SubscribeSingleDamagerMob(mob,Mob_Damaging);
		MobEventHelper.updateStat.SubscribeSingle(mob,Mob_UpdateStat);
		if(shooterMob) {
			mob.faction=shooterMob.faction;
		}
	}

	protected override void OnDisable() {
		base.OnDisable();
		ProjectilePool.Clear(prefab);
		Destroy(gameObject);
	}
	private void OnDestroy() {
		MobEventHelper.damaging.UnsubscribeSingleDamagerMob(mob,Mob_Damaging);
		MobEventHelper.updateStat.UnsubscribeSingle(mob,Mob_UpdateStat);
	}
	protected override void Update() {
		base.Update();
		transform.position-=(Vector3)velocity*Time.deltaTime;
	}

	override protected void UpdateStats() {
		transform.localScale=Vector3.one*stat.size;
	}

	protected override void FixedUpdate() {
		base.FixedUpdate();
	}
	protected override void UpdateHit() {
		if(doUpdateHit) base.UpdateHit();
	}
	protected override void UpdatePosition() { }

	void Mob_Damaging(object _sender,DamageEventArgs e) {
		//if(e.stat.attackerProjectile) return;
		if(e.stat.isComposition) return;
		e.stat.amount.AddAdd(stat.damage,float.MinValue);
	}

	void Mob_UpdateStat(object _sender,object e) {
		mob.speed=stat.speed;
	}

}
